package cn.itcast.oa.model;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name="itcast_privilege")
public class Privilege implements java.io.Serializable {
   
	private Long id;
     private String url;
     private String name;
     private String icon;//图标信息
     private Set<Role> roleList=new HashSet<Role>();
     private Privilege parent;
     private Set<Privilege> children=new HashSet<Privilege>();
     
     public Privilege(){
    	 
     }
     
     public Privilege(String name,String url,String icon,Privilege parent){
    	 this.name=name;
    	 this.url=url;
    	 this.icon=icon;
    	 this.parent=parent;
     }
     
     
     @Id
     @GeneratedValue
     public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	
	public String getUrl() {
		return url;
	}
	public void setUrl(String url) {
		this.url = url;
	}
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	public String getIcon() {
		return icon;
	}
	public void setIcon(String icon) {
		this.icon = icon;
	}
	
	@ManyToOne
	@JoinColumn(name="parentId")
	public Privilege getParent() {
		return parent;
	}
	public void setParent(Privilege parent) {
		this.parent = parent;
	}
	
	@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.EAGER,mappedBy="parent")
	public Set<Privilege> getChildren() {
		return children;
	}
	public void setChildren(Set<Privilege> children) {
		this.children = children;
	}
	
	@ManyToMany(mappedBy="privileges",fetch=FetchType.EAGER)
	public Set<Role> getRoleList() {
		return roleList;
	}
	public void setRoleList(Set<Role> roleList) {
		this.roleList = roleList;
	}
	
}
